package com.atguigu.job;

import com.atguigu.constant.RedisConstant;
import com.atguigu.util.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * 任务类：清理七牛云垃圾图片
 */
public class ClearImgJob {

    @Autowired
    JedisPool jedisPool;

    public void clearImg(){

        //存放垃圾图片名称
        Set<String> imgNameList = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if(imgNameList!=null && imgNameList.size()>0){
            for (String imgName : imgNameList) {
                System.out.println("清理垃圾图片 - imgName = " + imgName);
                QiniuUtils.deleteFileFromQiniu(imgName);
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,imgName);
            }
        }

    }
}
